home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96a.txt
/
000040_icon-group-sender _Thu Feb 8 12:06:34 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1996-09-05
|
3KB
Received: by cheltenham.cs.arizona.edu; Thu, 8 Feb 1996 12:21:59 MST
From: Nick Williams <nmw@styx.ios.com>
Message-Id: <199602081706.MAA01427@styx.ios.com>
Subject: Copying procedure blocks
To: icon-group@cs.arizona.edu
Date: Thu, 8 Feb 1996 12:06:34 -0500 (EST)
X-Mailer: ELM [version 2.4 PL23]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 2912
Errors-To: icon-group-errors@cs.arizona.edu
Status: O
Hi, several days ago I posted a note about adding closures to Icon as a
feature. Since then I have realized that it would indeed be much easier
to make it so that invoking copy() with a procedure as an argument would
return a new procedure block with new copies of any static variables.
It has taken me some time to figure out how to do it, but in the end it
is relatively simple. I've changed a few lines of code and what I have
works, except for a few small bugs that I hope someone can help me with.
The main bug is that garbage collection causes core dumps if it also
causes procedure blocks to move around; the other main bug is that I
have not at all delved into how the compiler works, so this feature is
only available with the interpreter.
Here's all I did:
1) changed src/icont/lcode.c to output &null descriptors at the end of
b_proc structures after the descriptors of local/static/argument
names (and adjusting the blksize field accordingly).
2) changed the implementation of the Op_Static and Op_Astatic Icon
virtual machine instructions; instead of using the argument to index
a global table, Op_Static now uses the argument to index the set of
descriptors at the end of the b_proc structure of the current
procedure.
3) changed the copy() function to actually make a new copy of its
argument if it is a procedure.
I have yet to go change getvar() and get_name() so that they work with
this scheme, but that too is a fairly simple task. I also intend to
change the implementation of Op_Init and of the refresh operation so
that new copies of procedures can be "refreshed."
I have assumed a few things: a) that the garbage collector will continue
to function correctly, since it will sweep the new descriptors at the
end of b_proc sturctures because it uses the blksize field to know when
to stop; and b) that "argp[0]" points to the b_proc structure of the
procedure in whose scope Op_Static and Op_Astatic are being called; and
c) that "argp[0]" is updated if the structure it points to is moved as a
result of a garbage collection event.
The changes I have made, btw, fit in one printed page and what remains
to be done to make this scheme work should be just as simple. I just
can't get past why I get these core dumps when procedure blocks are
relocated during garbage collection. If anyone is interested I will post
a set of diffs showing the changes I have made.
I plan to use this feature to, among other things, implement a dynamic
RPC mechanism.
Nick
PS: as this hack stands it involves changes these source files:
src/icont/lcode.c:lemitproc()
src/runtime/interp.r:interp() [Op_Static and Op_Astatic]
src/runtime/fmisc.r:copy()
I will also change:
src/runtime/rmisc.r:get_var()
src/runtime/rdebug.r:getname()
src/runtime/interp.r:interp() [Op_Init]
src/h/rstructs.r:struct b_proc [to add a field to help with Op_Init]